<?php
include ("../db/DbManage.php");
class MovieService{
    //获取所有电影票信息
    public function getATicket($user_id){
        $db=new DbManage();
        $sqlTxt=
            "SELECT
                    a.cinema_name,
                    b.movie_name,
                    c.seat_row ,
                    c.seat_column
                FROM
                    cinema_info a,
                    movie_info b,
                    seat_info c 
                WHERE
                    a.cinema_id = c.cinema_id 
                    AND b.movie_id = c.movie_id 
                    AND c.user_id = ".$user_id;
        $result=$db->executeSqlTxt($sqlTxt);
        $aTicket = array();
        while ($row = mysqli_fetch_array($result)){
            array_push($aTicket, $row);
        }
        return $aTicket;
    }
    //获取座位信息
    public function getSeatInfo($cinema_id,$movie_id,$user_id){
        $sqlTxt="select seat_row,seat_column from seat_info where cinema_id=".$cinema_id." and movie_id=".$movie_id;
        $db = new DbManage();
        $result = $db->executeSqlTxt($sqlTxt);
        $seatInfo=array();
        while ($row = mysqli_fetch_array($result)){
            array_push($seatInfo,$row);
        }
        return $seatInfo;
    }
    //获取电影院名字
    public function getCinemaById($cinema_id){
        $sqlTxt="select * from cinema_info where cinema_id=".$cinema_id;
        $db = new DbManage();
        $result = $db->executeSqlTxt($sqlTxt);
        $row = mysqli_fetch_array($result);
        $CinemaName = $row['cinema_name'];
        return $CinemaName;
    }
    //获取所有电影院信息
    public function getACinemaInfo(){
        $sqlTxt="select * from cinema_info";
        $db = new DbManage();
        $result = $db->executeSqlTxt($sqlTxt);
        $aCinema = array();
        while ($row = mysqli_fetch_array($result)){
            array_push($aCinema, $row);
        }
        return $aCinema;
    }
    //获取单个电影所有信息
    public function getMovieInfo($movie_id){
        $sqlTxt = "select * from movie_info where movie_id=".$movie_id;
        $db = new DbManage();
        $result = $db->executeSqlTxt($sqlTxt);
        $row = mysqli_fetch_array($result);
        return $row;
    }
    //获取所有电影所有信息
    public function getAMovieInfo(){
        $sqlTxt = "select * from movie_info";
        $db = new DbManage();
        $result = $db->executeSqlTxt($sqlTxt);
        $aMovie = array();
        while ($row = mysqli_fetch_array($result)){
            array_push($aMovie, $row);
        }
        return $aMovie;
    }
    //获取电影数量
    public function getMovieNum(){
        $sqlTxt="select count(*) as movieNum from movie_info";
        $db = new DbManage();
        $result = $db->executeSqlTxt($sqlTxt);
        $returnValue=0;
        while ($row = mysqli_fetch_array($result)){
            $returnValue = $row["movieNum"];
            break;
        }
        return $returnValue;
    }
    //获取电影名字
    public function getMovieName($movie_id){
        $db=new DbManage();
        $sqlTxt="select movie_name from movie_info where movie_id=".$movie_id;
        $result=$db->executeSqlTxt($sqlTxt);
        $row = mysqli_fetch_array($result);
        return $row['movie_name'];
    }
//    public function countMoviesByStatus($status){
//        $db = new DbManage();
//        $sqlTxt = "select count(*) as movies from movie_info where m_status=" . $status;
//        $result = $db->executeSqlTxt($sqlTxt);
//        $returnValue = 0;
//        while ($row = mysqli_fetch_array($result)){
//            $returnValue = $row["movies"];
//            break;
//        }
//        //$db->closeConnection(true);
//        return $returnValue;
//    }
//    public function getTop5MoviesByStatus($status){
//        $db = new DbManage();
//        $sqlTxt = "select * from movie_info where m_status=" . $status;
//        $result = $db->executeSqlTxt($sqlTxt);
//        $movieList = array();
//        while ($row = mysqli_fetch_array($result)){
//            array_push($movieList, $row);
//        }
//        //$db->closeConnection(true);
//        return $movieList;
//    }
//    //票房。可以根据日期传入，灵活统计，请同学们自己设计并完成该功能
//    public function getTop10MoviePf($start_date, $end_date){
//        $db = new DbManage();
//        $sqlTxt = "select t.movie_id,SUM(movie_current_pf) as moneys, mi.movie_name  ".
//            "  from movie_pf_info t INNER JOIN movie_info mi ON t.movie_id = mi.movie_id ".
//            "  where t.movie_pf_date <= str_to_date('". $end_date . "', '%Y-%m-%d')".
//            "  and t.movie_pf_date >=str_to_date('". $start_date . "', '%Y-%m-%d')".
//            "  and p_status = 1 ".
//            "  GROUP BY t.movie_id, mi.movie_name ".
//            "  order by moneys desc limit 0, 10";
//        //echo $sqlTxt;
//        $result = $db->executeSqlTxt($sqlTxt);
//        $moviePfList = array();
//        while ($row = mysqli_fetch_array($result)){
//            array_push($moviePfList, $row);
//        }
//        //$db->closeConnection(true);
//        return $moviePfList;
//    }
//
//    public function getHotPreMovie(){
//        $db = new DbManage();
//        $sqlTxt = "SELECT pv.P_v_id, P_v_url,  mi.movie_name, mi.movie_id".
//            "   from p_v_info pv INNER JOIN movie_info mi ON pv.Movie_id=mi.movie_id ".
//	        "   ORDER BY P_v_id DESC".
//	        "   LIMIT 0, 6 ";
//        $result = $db->executeSqlTxt($sqlTxt);
//        $hotPreMovieList = array();
//        while ($row = mysqli_fetch_array($result)){
//            array_push($hotPreMovieList, $row);
//        }
//        //$db->closeConnection(true);
//        return $hotPreMovieList;
//    }
//
//    public function getChangciList($movie_id, $cinema_id, $start_date, $end_date){
//        $db = new DbManage();
//        $sqlTxt = "SELECT m.movie_id, m.movie_name, m.type, ci.Changci_id, ci.Play_datetime,"
//            ."   ci.S_h_id, sh.S_h_name, sh.Cinema_id, cm.Cinema_name "
//            ."   FROM movie_info m INNER JOIN changci_info ci "
//		    ."   ON ci.Movie_id = m.movie_id AND ci.C_ststus = 1"
//	        ."   INNER JOIN screening_hall_info sh "
//		    ."     ON sh.S_h_id =ci.Changci_id and ci.C_ststus = 1"
//	        ."   INNER JOIN cinema_info cm ON cm.Cinema_id=sh.Cinema_id"
//	        ."   WHERE m.m_status = 1 and ci.Play_datetime >= " . $start_date . " "
//	        ."   AND ci.Play_datetime < " . $end_date . " "
//	        ."   AND ci.Movie_id = " . $movie_id
//            ."   AND cm.Cinema_id = " . $cinema_id . " ";
//
//        $result = $db->executeSqlTxt($sqlTxt);
//        $playList = array();
//        while ($row = mysqli_fetch_array($result)){
//            array_push($playList, $row);
//        }
//        return $playList;
//    }

}